package cn.zhiwen.stream;

import cn.zhiwen.entity.Person;

import java.util.ArrayList;
import java.util.List;

public class StreamManOrMin {
    public static void main(String[] args) {
        List<Person> javaProgrammers = new ArrayList<Person>() {
            {
                add(new Person("Elsdonds", "Jaycob", "Java programmer", "male", 43, 2000));
                add(new Person("Camsens", "Brittany", "Java programmer", "female", 23, 1500));
                add(new Person("Floyd", "Donny", "Java programmer", "male", 33, 1800));
                add(new Person("Sindy", "Jonie", "Java programmer", "female", 32, 1600));
                add(new Person("Vere", "Hervey", "Java programmer", "male", 22, 1200));
                add(new Person("Maude", "Jaimie", "Java programmer", "female", 27, 1900));
                add(new Person("Shawn", "Randall", "Java programmer", "male", 30, 2300));
                add(new Person("Bayden", "Corrina", "Java programmer", "female", 35, 1700));
                add(new Person("Palmer", "Dene", "Java programmer", "male", 33, 2000));
                add(new Person("Addison", "Pam", "Java programmer", "female", 34, 1300));
            }
        };
        System.out.println("工资最低的 Java programmer:");
        Person person = javaProgrammers.stream().min((p1, p2) -> (p1.getSalary() - p2.getSalary())).get();
        System.out.println(person.getSalary());

        System.out.println("工资最高的 Java programmer:");
        Person person1 = javaProgrammers.stream().max((p1, p2) -> (p1.getSalary() - p2.getSalary())).get();
        System.out.println(person1.getSalary());
    }
}
